-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Splitter Adjustments #457
Conversation
…-empty checks to avoid zero send messages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! One small thing I noticed while reviewing:
let distro_msg = pkt.to_sub_msg(kernel_address, Some(amp_funds), 1)?; |
This packet might actually end up being empty. In which case we should probably skip attaching it.
This and changelog entry and should be good to merge!
WalkthroughThe recent updates to the Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let amount_owed = coin.amount.mul_floor(recipient_percent); | ||
if !amount_owed.is_zero() { | ||
let mut recip_coin: Coin = coin.clone(); | ||
recip_coin.amount = amount_owed; | ||
remainder_funds[i].amount = | ||
remainder_funds[i].amount.checked_sub(recip_coin.amount)?; | ||
vec_coin.push(recip_coin.clone()); | ||
amp_funds.push(recip_coin); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optimize nested loops to improve performance.
Consider using a HashMap
to store and update remainder_funds
to avoid nested loops and improve performance.
let mut remainder_funds_map: HashMap<String, Uint128> = info.funds.iter().map(|coin| (coin.denom.clone(), coin.amount)).collect();
for recipient_addr in &splitter.recipients {
let recipient_percent = recipient_addr.percent;
let mut vec_coin: Vec<Coin> = Vec::new();
for coin in info.funds.iter() {
let amount_owed = coin.amount.mul_floor(recipient_percent);
if !amount_owed.is_zero() {
let mut recip_coin = coin.clone();
recip_coin.amount = amount_owed;
if let Some(remainder) = remainder_funds_map.get_mut(&coin.denom) {
*remainder = remainder.checked_sub(amount_owed)?;
}
vec_coin.push(recip_coin.clone());
amp_funds.push(recip_coin);
}
}
if !vec_coin.is_empty() {
let amp_msg = recipient_addr.recipient.generate_amp_msg(&deps.as_ref(), Some(vec_coin))?;
pkt = pkt.add_message(amp_msg);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review Details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- CHANGELOG.md (1 hunks)
Additional Context Used
LanguageTool (7)
CHANGELOG.md (7)
Near line 12: Unpaired symbol: ‘]’ seems to be missing
Context: ...## Added - Added Validator Staking ADO [(#330)](https://github.com/andromedaprot...
Near line 13: Unpaired symbol: ‘]’ seems to be missing
Context: ...eda-core/pull/330) - AddedAsset
enum [(#415)](https://github.com/andromedaprot...
Near line 14: Unpaired symbol: ‘]’ seems to be missing
Context: ...ddedADOBaseVersion
query to all ADOs [(#416)](https://github.com/andromedaprot...
Near line 15: Unpaired symbol: ‘]’ seems to be missing
Context: ... ability to remove/replace reward token [(#418)](https://github.com/andromedaprot...
Near line 16: Unpaired symbol: ‘]’ seems to be missing
Context: ...meda-core/pull/418) - Added Expiry Enum [(#419)](https://github.com/andromedaprot...
Near line 20: Unpaired symbol: ‘]’ seems to be missing
Context: ... Merkle Root: stage expiration now usesMilliseconds
[(#417)](https://github.com/andromedaprot...
Near line 24: Unpaired symbol: ‘]’ seems to be missing
Context: ...d messages, owner updates lock any time [(#457)](https://github.com/andromedaprot...
- Splitter: avoid zero send messages, owner updates lock any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct the grammar and punctuation in the change description.
- Splitter: avoid zero send messages, owner updates lock any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457)
+ Splitter: avoid zero send messages; owner can update lock at any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457)
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.
- Splitter: avoid zero send messages, owner updates lock any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457) | |
Splitter: avoid zero send messages; owner can update lock at any time [(#457)](https://github.com/andromedaprotocol/andromeda-core/pull/457) |
I assume that's also applicable to the conditional splitter? |
Yea I'd assume so |
Motivation
There were cases where zero send messages could be sent, contract owner couldn't update lock at any time.
Implementation
Use
.mul_floor
to multiplyUint128
withDecimal
Removed check that prevented the contract owner to update lock at any time
Set non-zero and non-empty checks to prevent zero send messages.
Testing
No new tests were created.
Notes
The above changes were requested through this comment
Summary by CodeRabbit
Bug Fixes
Refactor